package ac.github.os.internal.core.holder.damage

import ac.github.os.internal.core.holder.EventHolder
import ac.github.os.internal.core.holder.Holder
import org.bukkit.entity.LivingEntity
import org.bukkit.entity.Projectile
import org.bukkit.event.Event
import org.bukkit.event.entity.EntityDamageByEntityEvent

abstract class DamageHolder(
    override val event: EntityDamageByEntityEvent
) : EventHolder<EntityDamageByEntityEvent> {

    val damager: LivingEntity
        get() = if (isProjectile) (projectile.shooter!! as LivingEntity) else event.damager as LivingEntity

    val entity: LivingEntity
        get() = event.entity as LivingEntity

    override val namespace: String
        get() = "player damage"

    val isProjectile: Boolean
        get() = event.damager is Projectile

    val projectile: Projectile
        get() = event.damager as Projectile

    fun setDamage(damage: Double) {
        event.damage = damage
    }


}